"""
应用配置管理
"""
import os
from typing import List
from pydantic_settings import BaseSettings


class Settings(BaseSettings):
    """应用配置类"""
    
    # 应用基础配置
    APP_NAME: str = "FastAPI1"
    APP_VERSION: str = "1.0.0"
    DEBUG: bool = True
    HOST: str = "0.0.0.0"
    PORT: int = 8000
    
    # 数据库配置
    TORTOISE_ORM: dict = {
        'connections': {
            'default': {
                # 'engine': 'tortoise.backends.asyncpg',  PostgreSQL
                'engine': 'tortoise.backends.mysql',  # MySQL or Mariadb
                'credentials': {
                    'host': '127.0.0.1',
                    'port': '3306',
                    'user': 'root',
                    'password': '123456789',
                    'database': 'fastapi1',
                    'minsize': 1,
                    'maxsize': 5,
                    'charset': 'utf8mb4',
                    "echo": True
                }
            },
        },
        'apps': {
            'models': {
                'models': ['models.models'],
                'default_connection': 'default',

            }
        },
        'use_tz': False,
        'timezone': 'Asia/Shanghai'
    }
    
    # 安全配置
    SECRET_KEY: str = "your-secret-key-here-change-in-production"
    ALGORITHM: str = "HS256"
    ACCESS_TOKEN_EXPIRE_MINUTES: int = 30
    
    # CORS 配置
    ALLOWED_ORIGINS: List[str] = ["http://localhost:3000", "http://localhost:8080"]
    
    # 日志配置
    LOG_LEVEL: str = "INFO"
    
    class Config:
        env_file = ".env"
        case_sensitive = True


# 创建全局配置实例
settings = Settings()
